<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery-2.0.0.min.js"></script>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        .big {
            display: flex;
            flex-direction: row;
            margin: auto;
            margin-top: 100px;
            justify-content: space-between;
            flex-wrap: wrap;
            width: 460px;
            height: 260px;
            row-gap: 20px;
            background-color: yellow;
            position: relative;
        }

        .item {
            width: 100px;
            height: 120px;
            background-color: lime;
            position: absolute;
            transition: all 1s;
        }
    </style>
</head>

<body>
    <div class="big">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
        <div class="item">5</div>
        <div class="item">6</div>
        <div class="item">7</div>
        <div class="item">8</div>
    </div>
    <script>
        let row = 0;
        let num = 0;
        $(".item").each(function (i, e) {

            setTimeout(function () {
                if (i % 4 == 0) {
                    num++;
                    row = num - 1;
                    console.log(row);
                }
                if (i < 4) {
                    $(".item").eq(i).css({
                        "top": "0px",
                        "left": i * ($(".item").eq(0).width() + 20) +
                            "px",
                    })
                } else {
                    $(".item").eq(i).css({
                        "top": row * ($(".item").eq(i - 4).height() + 20) + "px",
                        "left": (i % 4) * ($(".item").eq(0).width() + 20) + "px",
                    })
                    // console.log(($(".item").eq(i - 4).offset().top - 100) + $(".item").eq(i - 4).height() + 20)
                }
            })
        })
    </script>
</body>

</html>